package fch;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that the CrazyTracker robot can reliably beat the sample Fire robot in a one-on-one
 * fight.  Adapted from the robocode-pmj-dacruzer's TestDaCruzerVersusSittingDuck.
 * @author Christopher Foo
 *
 */
public class TestCrazyTrackerVersusFire extends RobotTestBed {


  @Override
  /**
   * Check that CrazyTracker was in first place for the battle and won at least 80% of the rounds.
   * @param event Details about the completed battle.
   */
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is CrazyTracker (i.e. in first place).
    BattleResults crazyTrackerResults = battleResults[1];
    String robotName = crazyTrackerResults.getTeamLeaderName();
    assertEquals("Check that results[1] is CrazyTracker", robotName, "fch.CrazyTracker*");
    assertEquals("Check that Crazytracker is in first place", 1, crazyTrackerResults.getRank());
    
    // Check to make sure CrazyTracker won at least 80% of the rounds.
    assertTrue(crazyTrackerResults.getFirsts() > getNumRounds() * 0.8);
  }

  @Override
  /**
   * Use Fire and CrazyTracker for this test.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  public String getRobotNames() {
    return "sample.Fire,fch.CrazyTracker";
  }

  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
}
